<?php

// R0910CMS 
// created by TLightSky
// time : 20100120

if(!defined("IN_R0910CMS")) {
    exit("Access Denied!");
}

class R_Db_CellFactory {
    /**
     *@param $checkType the check type
     *       $len length of the value OR type and length. 
     *@return Cell Instance
     */
    public function get($checkType, $len=null) {
        $cell = new R_Db_Cell();
        $cell->sqlStr = self::getCellSql($checkType, $len);

        $cell->checkFunc = R_Db_DataCheck::getCheckFunc($checkType);
        return $cell;
    }
	/**
	 *@param $checkType R_Db_DataCheck::INTEGER
	 *       $len 10 OR VARCHAR(10)
	 *@return the string like: VARCHAR(10)
	 */
    private function getCellSql($checkType, $len=null) {
        //echo "\n---$checkType $len ----\n";
        if(R_Db_DataCheck::checkInteger($len)||empty($len)){
			$type = $ret = "";
			if(R_Db_DataCheck::INTEGER == $checkType){
				$type = 'INT';
                $len = $len?$len:11;
			} elseif (R_Db_DataCheck::STRING == $checkType) {
				$type = 'VARCHAR';
                $len = $len?$len:255;
			} elseif (R_Db_DataCheck::FLOAT  == $checkType) {
				$type = 'FLOAT';
			} else {
				$type = 'TEXT';
			}
            if(!empty($len)) {
                $ret = join('',array( $type ,'(', $len, ')' ));
            } else {
                return $type;
            }
			return $ret;
        } else {
            return $len;
        }
    }
}

